<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/elementUI.css">
    <script src="/js/vue.js"></script>
    <script src="/js/elementUI.js"></script>
    <script src="/js/axios.js"></script>
</head>
<body>

<div id="app">
    手机号：<el-input v-model="form.phone" style="width:200px"></el-input>
    <br>
    验证码：<el-input v-model="form.code" style="width:200px"></el-input> <el-button @click="sendCode">发送验证码</el-button>
    <br>
    <el-button type="primary" @click="login">登录</el-button>


</div>
<script>
    new Vue({
        el:"#app",
        data:{
            form:{
                phone:"",
                code:""
            }
        },
        watch:{
        },
        methods:{
            sendCode(){
                axios.post("/user/sendCode?phone="+this.form.phone).then(res=>{
                    var r = res.data;
                    if(r.code==0){
                        this.$message.success("发送成功，验证码是："+r.data)
                    }else{
                        this.$message.error(r.message)
                    }
                })
            },
            login(){
                axios.post("/user/login?code="+this.form.code,this.form).then(res=>{
                    var r = res.data;
                    if(r.code==0){
                        this.$message.success("登录成功")
                        var user = r.data;
                        localStorage.setItem("currentUser",JSON.stringify(user));
                        setTimeout(()=>{
                            location.href = "goods.html"
                        },2000)
                    }else{
                        this.$message.error(r.message)
                    }
                })

            }

        },
        created(){
        }
    })
</script>

</body>
</html>
